<template>
  <el-table :data="get_specsList" border style="width: 100%">
    <el-table-column prop="id" label="规格编号" width="100"></el-table-column>
    <el-table-column prop="specsname" label="规格名称" width="180"></el-table-column>
    <el-table-column prop="attrs" label="规格属性">
      <template v-slot="item">
        <el-button type="info" plain size="small" v-for="it in item.row.attrs" :key="it">{{ it }}</el-button>
      </template>
    </el-table-column>
    <el-table-column prop="status" label="状态">
      <template v-slot="item">
        <el-button type="primary" plain size="small" v-if="item.row.status == 1">启用</el-button>
        <el-button type="danger" plain size="small" v-else>禁用</el-button>
      </template>
    </el-table-column>
    <el-table-column  label="操作">
      <template v-slot="item">
        <el-button type="primary" size="small" @click="edit(item.row.id)">编辑</el-button>
        <el-button type="danger" size="small" @click="delItem(item.row.id)">删除</el-button>
      </template>
       
    </el-table-column>
  </el-table>
</template>

<script>
import { mapGetters,mapActions } from 'vuex';
import {specsdelete} from "@/request/api.js"
export default {
  data() {
    return {
      
    };
  },
  computed:{
    ...mapGetters("specs",["get_specsList"]) //获取商品规格数据
  },
  methods:{
    ...mapActions("specs",["action_specsList"]), //获取商品规格数据的方法
    //点击删除
    delItem(id){
      this.$confirm("是否删除该规格", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          try {
            let res = await specsdelete({ id });
            if (res.code == 200) {
              //提示，更新数据（重新请求数据）
              this.$message.success(res.msg);
              this.action_specsList();
            } else {
              this.$message.info(res.msg);
            }
          } catch (err) {
            this.$message.error(err);
          }
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    },
    edit(id){
      this.$emit("edit",id)
    }
  },
  mounted(){
    this.action_specsList();
  }
};
</script>

<style>
</style>